<%@page import="cn.lei.Student"%>
<%@page import="java.util.List"%>
<%@page import="cn.severimpl.StudentServiceImpl"%>
<%@page import="cn.isever.IStudentService"%>
<%@page import="org.eclipse.jdt.internal.compiler.batch.Main"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

		<link rel="stylesheet" type="text/css" href="lib/bootstrap/css/bootstrap.css" />
		<!--引入jquery-->
		<script type="text/javascript" src="lib/jquery-1.11.1.js" ></script>
		<!--引入js-->
		<script type="text/javascript" src="lib/bootstrap/js/bootstrap.js" ></script>
		<script type="text/javascript" src="../../jquery-1.11.1.js"></script>
		<script type="text/javascript">
		function deleteById(id){
			//用户点了确定，confirm返回的就是true
			//用户点了取消，confirm返回的就是false
			var isDel = confirm("您确认要删除吗?");
			if(isDel){
				location.href = "<%=request.getContextPath() %>/student?method=deleteById&id="+id;
			}
		}
		
		function checkall(){
			$(".checkall").prop("checked",true);
		}
		function unclick(){
			$(".checkall").prop("checked",false);
		}
		
		function fanxuan(){
			  //反选
            //遍历全部复选框，选中就取消，未选中就设置选中
            var fan = document.getElementsByClassName("checkall");
				for (var i = 0; i < fan.length; i++) {
					//checkboxs[i].checked == true ? checkboxs[i].checked = false : checkboxs[i].checked = true; 
					var checkedStatus = fan[i].checked;
					if(checkedStatus){
						fan[i].checked=false;
						
					}else{
						fan[i].checked=true;
					}
				}
			}
           		
           		
           
		
		
		
		</script>
</head>
<body>
 <!-- JSP脚本 -->
 
 <!-- JSP表达式 -->

<%
		List<Student> list = (List<Student>)request.getAttribute("list");
	%>
	<a href="student_add.jsp">添加</a>
	<form action="<%=request.getContextPath() %>/student?method=list"  method="post">
		姓名:<input type="text" name="name"/>
		<input type="submit" value="搜索"/>
	
	</form>
<!-- 遍历List<Student>集合 -->
	<button onclick="fanxuan()">反选</button>
		<table class="table table-striped table-bordered table-hover table-condensed">
		<tr>
			<td>全选/双击多选<input type="checkbox" onclick="checkall()" ondblclick="unclick()" />反选<input type="checkbox" /></td>
			<td>ID</td>
			<td>姓名</td>
			<td>年龄</td>
			<td>性别</td>
			<td>修改</td>
			<td>删除</td>
		</tr>
		<%
		for(Student student:list){
		%>
		<tr>
			<td><input type="checkbox" class="checkall"  name = "checkall"/></td>
			<td><%=student.getId()%></td>
			<td><%=student.getName()%></td>
			<td><%=student.getAge()%></td>
			<td><%=student.getGender()%></td>
			<td><a href="<%=request.getContextPath() %>/student?method=toUpdate&id=<%=student.getId()%>">修改</a></td>
			<td><a href="javascript:deleteById(<%=student.getId()%>)">删除</a></td>
		</tr>
		<% 
		}
		%>
		</table> 
		 <ul class="pagination">
		    <li>
		      <a href="#" aria-label="Previous">
		        <span aria-hidden="true">&laquo;</span>
		      </a>
		    </li>
		    <li><a href="#">1</a></li>
		    <li><a href="#">2</a></li>
		    <li><a href="#">3</a></li>
		    <li><a href="#">4</a></li>
		    <li><a href="#">5</a></li>
		    <li>
		      <a href="#" aria-label="Next">
		        <span aria-hidden="true">&raquo;</span>
		      </a>
		    </li>
		  </ul>
		
</body>
</html>